/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author jefoutta
 */
import java.util.*;

public class Not extends LogicGate{

    public Not(String tname){
        this.numEntries = 1;
        this.input = new int[1];
        this.inputAvailable = new boolean[1];
        this.delayDown = new int[1];
        this.delayUp = new int[1];
        this.outputChannels = new ArrayList(0);
        this.inputChannels = new ArrayList();
        this.type = 1;
        this.type = 3;
        this.input[0] = -1;
        this.inputAvailable[0] = true;
        this.output = -1;
        this.pathCount = 0;
        this.name = tname;
    }

    public int getOutput(){
        int temp = 2;
        if(this.input[0] == 0)
            temp = 1;
        if(this.input[0] == 1)
            temp = 0;
        return temp;
    }

    public void sensitizeEntry(int index){
        this.input[index] = 2;
    }

    public void justifyFromOutput(int outputVal){
        System.out.println("entro a justify " + this.name +  " val:" +outputVal);
        this.output = outputVal;
        switch(this.input[0]){
            case -1:{
                if(this.output == 1){
                    this.input[0] = 0;
                }
                if(this.output == 0){
                    this.input[0] = 1;
                }
                if(this.output == 2){
                    this.input[0] = 2;
                }
                this.propagateIn(0);
            }break;
            case 0:{
                if(this.getOutput() != this.output){
                    this.setError(true);
                }
            }break;
            case 1:{
                if(this.getOutput() != this.output){
                    this.setError(true);
                }
            }break;
            case 2:{
                if(this.output != 2){
                    this.setError(true);
                }
            }
        }

        if(this.bigError){
            System.out.println("salio con error de justify " +this.name);
        }else System.out.println("salio con exito de justify");
    }
}
